package SiTuQingYou.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import SiTuQingYou.dao.UserDao;
import SiTuQingYou.vo.Question;
import SiTuQingYou.vo.User;

/**
 * Servlet implementation class RegisterServlet
 */
@WebServlet("/RegisterServlet")
public class RegisterServlet extends BaseAction {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegisterServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	

	
	protected void toCheckUsername(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter out = response.getWriter();
		
		String username = request.getParameter("username");
		boolean f = UserDao.isRename(username);
		
		if(f==false)
		{
			out.print("0");//0����û���ظ�
		}
		else
		{
			out.print("1");//1�������ظ�
		}
	}
	
	
	protected void toRegisterNewCount(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String username = request.getParameter("username");//1�û���
		String userpass = request.getParameter("userpass");//2����
		String usersex = request.getParameter("usersex");//3�Ա�
		String userRealName = request.getParameter("userRealName");//4��ʵ����
		String userphone = request.getParameter("userphone");//5�ֻ���
		String usernickname = request.getParameter("usernickname");//6�ǳ�
		String userquestion = request.getParameter("userquestion");//7�ܱ�����
		String useranswer = request.getParameter("useranswer");//8�ܱ���
		
		User user = new User();
		user.setUsername(username);//1
		user.setUserpass(userpass);//2
		user.setUsersex(Boolean.parseBoolean(usersex));//3
		user.setUserrealname(userRealName);//4
		user.setUserphone(userphone);//5
		user.setUsernickname(usernickname);//6
        
        
        Question question = new Question();
        question.setId(Integer.parseInt(userquestion));//7
        user.setQuestion(question);
        
		user.setUseranswer(useranswer);//8
		
		UserDao.toRegisterNewCount(user);
		
		String path = request.getContextPath();
		response.sendRedirect(path+"/anotherLogReg/login.jsp?w=1");
		
	}
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doDefault(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stubr
		
	}

}
